/*
* Copyright 2016 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-wechat-open-api
*
* @File name : customerInfoController.java
*
* @Author : Administrator
*
* @Date : 2016年11月25日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016年11月25日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmcc.gateway.wechat.controller.customerinfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.marketing.common.constants.BusinessConstant;
import org.marketing.common.dto.customerInfo.CounselorDto;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmcc.gateway.wechat.common.ApiVersionConsts;
import com.yonyou.gmcc.gateway.wechat.controller.BaseController;
import com.yonyou.gmcc.gateway.wechat.service.interfaces.CounselorServiceInterface;

/**
*
* @author QianKun
* 销售/售后顾问API-接口
* @date 2016年11月25日
*/
@RestController
@RequestMapping(value = ApiVersionConsts.BASE_PATH+"/potentialUsers/counselor")
public class CounselorController extends BaseController{
    private Logger logger = Logger.getLogger(CounselorController.class);
    @Autowired
    private CounselorServiceInterface counselorServiceInterface;
    
    /**
    *
    * @author QianKun
    * 销售/售后顾问保存
    * @date 2016年11月29日
    * @param counselorDto
    * @return
    * @throws Exception
    */
    @RequestMapping(method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public @ResponseBody Map<String,Object> saveCounselor(@RequestBody CounselorDto counselorDto) throws Exception {
        
        Map<String,Object> resultMap = counselorServiceInterface.saveCounselor(counselorDto);
        return resultMap;
    }

    /**
    *
    * @author QianKun
    * 销售/售后顾问查询
    * @date 2016年11月25日
    * @param potentialUserId
    * @param positionId
    * @return
    */
    @RequestMapping(value = "/selectCounselor", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<CounselorDto> getCounselorData(@RequestParam("positionId") String positionId ,HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<CounselorDto> dtoList = null;
        this.logger.info(this.getClass().getName()+":BEGIN");
        try{
            String dealerCode = "270001";
            //String dealerCode = this.getDealerCode(request);
            if(CheckUtil.NullOrEmpty(dealerCode)){
                dealerCode = BusinessConstant.EMPTY_STRING;
            }
            this.logger.info("dealerCode:"+dealerCode);
            this.logger.info("positionId:"+positionId);
            dtoList = counselorServiceInterface.getCounselorData(dealerCode,positionId);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        }catch(Exception e){
            this.logger.error(e.getMessage(),e);
            throw e;
        }
        return dtoList;
    }
    
    
    /**
    * 用户目前销售顾问查询
    * @author QianKun
    * @date 2016年12月22日
    * @param potentialUserId
    * @return
    * @throws Exception
    */
    @RequestMapping(value = "/selectSalesCounselor", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<CounselorDto> getSalesCounselorData(HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<CounselorDto> dtoList = null;
        try{
            Long potentialUserId = this.getPotentialUserId(request);
            dtoList = counselorServiceInterface.getSalesCounselorData(potentialUserId);
            if (CheckUtil.NullOrEmpty(dtoList)) {
                dtoList = new ArrayList<>();
            }
        }catch(Exception e){
            this.logger.error(e.getMessage(),e);
            throw e;
        }
        return dtoList;
    }
    
    /**
    * 用户目前售后顾问查询
    * @author QianKun
    * @date 2016年12月22日
    * @param potentialUserId
    * @return
    * @throws Exception
    */
    @RequestMapping(value = "/selectAfterSaleCounselor", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<CounselorDto> getAfterSaleCounselorData(HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<CounselorDto> dtoList = null;
        try{
            Long potentialUserId = this.getPotentialUserId(request);
            dtoList = counselorServiceInterface.getAfterSaleCounselorData(potentialUserId);
            if (CheckUtil.NullOrEmpty(dtoList)) {
                dtoList = new ArrayList<>();
            }
        }catch(Exception e){
            this.logger.error(e.getMessage(),e);
            throw e;
        }
        return dtoList;
    }
}
